extends Control

var peer = ENetMultiplayerPeer.new()
var port = 8088

var account_data = {
	"舒荣森":{
		"name":"舒荣森",
		"password":"123",
		"this_ID":0,
		"position":"0,0",
		"map_name":"null"
	},
	"测试":{
		"name":"测试",
		"password":"123",
		"this_ID":0,
		"position":"0,0",
		"map_name":"null"
		
	}
}


var map_data = {
	"测试地图":{}
}
#玩家加入地图
func join_Map(mapName,userName):
	if map_data.has(mapName):
		
		account_data[userName].map_name = mapName
		map_data[mapName][userName] = {
			"name":userName,
			"position":account_data[userName].position,
			"this_ID":account_data[userName].this_ID
		}
		GlobalPopup.print_text("玩家:"+userName+"加入地图"+"mapName")
	else:
		GlobalPopup.print_text("找不到地图"+mapName)
		
#获取对应地图内所有玩家
func get_map_user(mapName,id):
	if map_data.has(mapName):
		Global.set_map_user.rpc_id(id,map_data[mapName])
		#GlobalPopup.print_text("地图内玩家信息以分发")
	#else:
		#GlobalPopup.print_text("找不到地图")


func _ready():
	GlobaWeb.server = self
	if peer.create_server(port):
		GlobalPopup.print_text("创建服务器失败，请检查端口！")
	else:
		multiplayer.multiplayer_peer = peer
		multiplayer.peer_connected.connect(ip_connection)
		GlobalPopup.print_text("创建服务器成功")
	
#当有IP连接到服务器时
func ip_connection(id):
	GlobalPopup.print_text("有ip:"+str(id)+"试图连接游戏")


